﻿using System;
using System.ComponentModel;
using System.Xml.Linq;

namespace YArchitech.Temp.Fluid
{
	[DefaultProperty("Temperature")]
	public class Steam : IComparable
	{
		[Category("参数设置")]
		[DisplayName("温度(℃)")]
		[DefaultValue(100)]
		public int Temperature { get; set; }

		[Category("参数设置")]
		[DisplayName("压力(Pa)")]
		[DefaultValue(0)]
		public double Pressure { get; set; }

		[Category("参数设置")]
		[DisplayName("密度(kg/m³)")]
		[DefaultValue(0)]
		public double Density { get; set; }

		[Category("参数设置")]
		[DisplayName("汽化热(kJ/kg)")]
		[DefaultValue(0)]
		public double Qhr { get; set; }

		[Category("参数设置")]
		[DisplayName("比热容kJ/(kg*K)")]
		[DefaultValue(0)]
		public double SpecificHeat { get; set; }

		[Category("参数设置")]
		[DisplayName("运动黏度(1E-6㎡/s)")]
		[DefaultValue(0)]
		public double Viscosity { get; set; }

		public int CompareTo(object obj)
		{
			if (obj is Steam)
			{
				Steam steam = obj as Steam;
				return this.Temperature - steam.Temperature;
			}
			return 1;
		}

		public static bool operator <(Steam left, Steam right)
		{
			return left.Temperature < right.Temperature;
		}

		public static bool operator >(Steam left, Steam right)
		{
			return left.Temperature > right.Temperature;
		}

		public bool ReadXml(XElement xe)
		{
			this.Temperature = (int)xe.Attribute("Temperature");
			this.Density = (double)xe.Attribute("Density");
			this.SpecificHeat = (double)xe.Attribute("SpecificHeat");
			this.Viscosity = (double)xe.Attribute("Viscosity");
			this.Qhr = (double)xe.Attribute("Qhr");
			return true;
		}

		public bool WriteXml(XElement xe)
		{
			xe.Add(new XAttribute("Temperature", this.Temperature));
			xe.Add(new XAttribute("Density", this.Density));
			xe.Add(new XAttribute("SpecificHeat", this.SpecificHeat));
			xe.Add(new XAttribute("Viscosity", this.Viscosity));
			xe.Add(new XAttribute("Qhr", this.Qhr));
			return true;
		}
	}
}
